<?php


class MpController extends ControllerBase
{
    public function listAction(){
        $wxh_name = $this->request->get("wxh_name");
        $type = $this->request->get("type");
        $where = "";
        if ($wxh_name) {
            $where .= "and info.nick_name like '%{$wxh_name}%'";
        }
        if ($type) {
            $where .= "and info.type like '%{$type}%'";
        }
        $list = $this->db->fetchAll("SELECT app.* ,
                                            info.nick_name,
                                            info.principal_name,
                                            info.head_img,
                                            info.type
                                            from authorized_app as app
                                           LEFT JOIN authorized_app_info as info on app.app_id = info.app_id
                                           WHERE app.enabled = 1 {$where}");

//        //未绑定默认绑定第一个
//        $username = $this->getMobie();
//        if (empty($username)) {
//            $this->exitMessage(false, '用户信息错误');
//        }
//
//        $bind_exit = BindInfo::findFirst("username='{$username}'");
//        if (!$bind_exit) {
//            $bind_info = New BindInfo();
//            $bind_info->username = $username;
//            $bind_info->bind_app_id = $list[0]['app_id'];
//            $bind_info->save();
//        }

        $this->exitMessage(true, '', $list);
    }
}